package com.wanmait.zaisousuo.service.Impl;

import com.github.pagehelper.PageInfo;
import com.wanmait.zaisousuo.service.AdminService;
import com.wanmait.zaisousuo.util.SysContext;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.Timestamp;
import java.util.List;
import com.wanmait.zaisousuo.mapper.AdminMapper;
import com.wanmait.zaisousuo.pojo.Admin;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class AdminServiceImpl implements AdminService {

    @Resource
    private AdminMapper adminMapper;

    @Override
    public void insert(Admin object) {

    }

    @Override
    public void update(Admin object) {

    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public Admin findById(Integer id) {
        return null;
    }

    @Override
    public List<Admin> findAll() {
        return adminMapper.findAll();
    }

    @Override
    public List<Admin> findAll(Admin object) {
        return null;
    }

    @Override
    public int getDataCount() {
        return 0;
    }

    @Override
    public int getDataCount(Admin object) {
        return 0;
    }

    @Override
    public PageInfo<Admin> findList(int pageNum) {
        return null;
    }

    @Override
    public Admin login(Admin admin) {
        return adminMapper.checkLogin(admin);
    }

    //禁用/启用管理员
    @Override
    public String changeDisabled(Boolean flag, Integer adminId,String adminName) {
        adminMapper.changeDisabled(flag,adminId);
        return flag+"&split&"+adminName;
    }

    //添加管理员
    @Override
    public Integer addAdmin(Admin admin) {
        //判断用户名是否存在
        Admin admin1 = adminMapper.adminExistOrNot(admin.getAdminName());
        if(admin1!=null){//已存在
            return 1;
        }
        else{//不存在，去添加
            adminMapper.insert(admin);
            return 0;
        }
    }

    //修改本次登录时间和ip
    @Override
    public void updateLoginInfo(String lastLoginIp, Timestamp lastLoginTime,Integer id) {
        adminMapper.updateLoginInfo(lastLoginIp,lastLoginTime,id);
    }


    //更改管理员密码
    @Override
    public void changeAdminPassword(Integer id, String newPW) {
        adminMapper.changeAdminPassword(id,newPW);
    }
}
